Skip to content

[Auto Parallel] Add spmd rule No.12 for label_smooth and label_smooth ops. - #72845

Merged
luotao1 merged 13 commits into
PaddlePaddle:developfrom
ooooo-create:add_spmd_label_smooth
Jun 13, 2025
Merged

luotao1 merged 13 commits into
PaddlePaddle:developfrom
ooooo-create:add_spmd_label_smooth

Conversation

@ooooo-create

@ooooo-create ooooo-create commented May 21, 2025 •

Copy link
Copy Markdown
Collaborator

PR Category

Auto Parallel

PR Types

New features

Description

@paddle-bot

paddle-bot Bot commented May 21, 2025

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@ooooo-create ooooo-create changed the title [Auto Parallel] Add spmd rule No.7、12 for (label_smooth,expand_as) ops and their grad ops [Auto Parallel] Add spmd rule No.12 for label_smooth and label_smooth ops. Jun 5, 2025
}
SpmdInfo unary_spmd_info = ElementwiseUnaryInferSpmd(label);
unary_spmd_info.first.push_back(TensorDistAttr());
VLOG(4) << "LabelSmoothInferSpmd:";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to put this line before L30/L32 and make the logs more understandable? e.g.
before L30 VLOG(4) << "LabelSmoothInferSpmd call ElementwiseBinaryInferSpmd:"
before L32 VLOG(4) << "LabelSmoothInferSpmd call ElementwiseUnaryInferSpmd:"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!done

self.assertEqual(inferred_input_dist_attrs[1].dims_mapping, [-1, -1])
self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, 1, -1])

# shape: [16, 16, 16], [1, 16]. [0, 1, -1], [-1, 0] --> [0, 1, -1], [-1, -1], [0, 1, -1]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need more unit test case to check:
if # shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, 1], what result should be
if # shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, 0], what result should be
if # shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, -1], what result should be

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the second station # shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, 0]
Because of reuse the ElementwiseBinaryInferSpmd, now it will cause error now when meet 1 and 0 with same axes (due to the ShardingMergeForAxis).
The following error is below, and I check the error now rather than implement it

 (Unimplemented) Tensor Axis[c] is Sharded by two different mesh dimension [0] and [1]. (at ../paddle/phi/infermeta/spmd_rules/utils.cc:70)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the calculation logic of this operator, if # shape: [16, 16, 16], [1, 16] and dims_mapping: [0, -1, 1], [-1, 0] the result of dims_mapping should be [0, -1, 1], [-1, 1], [0, -1, 1]? if so, we should add some necessary checks and modifications to dims_mapping of prior_dist before calling ElementwiseBinaryInferSpmd?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. If # shape: [16, 16, 16], [1, 16] and dims_mapping: [0, -1, 1], [-1, 0] the result of dims_mapping should be [0, -1, 1], [-1, 1], [0, -1, 1]
If label's rank is greater than prior_dist's axis. It has an extra_dims_mapping. When prior_dist's dims_mappin in it, replicate it to -1 first. It will work better than before.
(In addition, I think in the future ElementwiseBinaryInferSpmd also should deal with this station

@ooooo-create

Copy link
Copy Markdown
Collaborator Author

/re-run all-failed

@jeff41404 jeff41404 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

check_dim_mapping(forward_info.first[0], {0, 1, -1});
const phi::distributed::ArgDistAttr& attr = forward_info.first[1];
if (paddle::holds_alternative<phi::distributed::TensorDistAttr>(attr)) {
EXPECT_EQ(paddle::get<phi::distributed::TensorDistAttr>(attr),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image @ooooo-create 下一个PR改一下吧

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的好的

@luotao1
luotao1 merged commit 0c0320f into PaddlePaddle:develop Jun 13, 2025
DrRyanHuang pushed a commit to DrRyanHuang/Paddle that referenced this pull request Jun 14, 2025
… ops. (PaddlePaddle#72845)

* add spmd_rule for label_smooth

* update

* fix bugs

* apply review

* revert due to PaddlePaddle#72753

* revert change for expand_as

* Add more tests

* apply review

* refine code
@ooooo-create
ooooo-create deleted the add_spmd_label_smooth branch September 29, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 skip-ci: xpu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants